﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ToolUltity;


namespace Medicare
{
    public partial class FrmLoginUser : Form
    {
        public FrmLoginUser()
        {
            InitializeComponent();
        }
        private LoginUser user = new LoginUser();
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.Empty.Equals(textBox5.Text.Trim()))
            {
                MessageBox.Show("无效的用户编号！");
                return;
            }
            string userName = LoginUser.USERNAME;
            if (!textBox4.Text.Equals(string.Empty))
            {
                userName = textBox4.Text; 
            }
            if (!textBox2.Text.Equals(textBox3.Text))
            {
                MessageBox.Show("二次输入的新密码不一致，请重新输入！");
                return;
            }
            if (LoginUser.USERID.Equals(textBox5.Text) && textBox5.Enabled==false)
            {
                int i = user.UpdateUser(LoginUser.USERID, textBox4.Text, textBox2.Text, textBox1.Text);
                if (i == -1)
                {
                    MessageBox.Show("没有找到登录的操作员信息！");

                }
                if (i == 1)
                {
                    MessageBox.Show("原密码错误！");
                }
                if (i == 0)
                {
                    MessageBox.Show("密码修改成功！");
                }
            }
            else
            {
                int i=user.SaveUser(textBox5.Text, userName, textBox1.Text);
                if (i==1)
                {
                    MessageBox.Show("已存在相同的操作员编号，请重新输入！");
                    return;
                }
                MessageBox.Show("操作成功！");
            }
             


        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
